/*
 * @Author: Jimmy
 * @LastModifiedBy: Jimmy
 * @Date: 2024-03-07 20:52:59
 * @LastEditTime: 2024-07-07 17:28:43
 * @FilePath: /nest_study/web/src/components/table_search/index.tsx
 */
import { Button, Flex } from 'antd'
import { SearchOutlined, ReloadOutlined, PlusOutlined, DeleteOutlined } from '@ant-design/icons';
import styles from './index.module.scss'
import SearchItem from '../search_item';

export default function TableSearch(props: any) {
    let {
        isExtra=true,
        isSearch = true,
        extraComponent,
        isDelete = true,
        deletePerm = 0,
        children,
    } = props;
    return (
        <Flex vertical gap={20} className={`${styles.table_search_frame}`}>
            <Flex wrap={"wrap"} gap={20} className={`${styles.search_header}`}>
                {
                    isSearch && (
                        <>
                            {children}
                            <SearchItem>
                                <Button className={`${styles.btn} search_btn`} type="primary" icon={<SearchOutlined />} onClick={() => props.search()}>搜索</Button>
                            </SearchItem>
                            <SearchItem>
                                <Button className={`${styles.btn}`} type="primary" ghost icon={<ReloadOutlined />} onClick={() => props.reset()}>重置</Button>
                            </SearchItem>
                        </>
                    )
                }
            </Flex>
            {
                isExtra && <Flex gap={20} wrap={"wrap"} className={`${!isSearch && styles.search_bottom} search_footer`}>
                    {
                        extraComponent ? extraComponent : (
                            <>
                                <Button type="primary" icon={<PlusOutlined />} onClick={() => props.add()}>新增</Button>
                                {
                                    isDelete && <SearchItem><Button className={`${styles.btn}`} type="primary" danger icon={<DeleteOutlined />} onClick={() => props.delete()} disabled={!deletePerm}>删除</Button></SearchItem>
                                }
                            </>
                        )
                    }
                </Flex>
            }
        </Flex>
    )
}
